<template>
  <div>
    <el-row type="flex" align="middle" class="title-item file-preview">
      <div class="picture">
        <el-image :src="row.cover_url">
          <el-row slot="error" type="flex" align="middle" justify="center" class="image-slot"><i class="el-icon-picture-outline" /></el-row>
        </el-image>
      </div>
      <el-row type="flex" justify="space-between" class="info">
        <el-tooltip effect="dark" :content="row.title" placement="bottom-start">
          <div class="name">{{ row.title }}</div>
        </el-tooltip>
        <el-row type="flex">
          <div>平台售价：</div><div class="scribing-price">{{ row.price | moneySymbol }}</div>
        </el-row>
      </el-row>
    </el-row>
    <div class="title-item file-preview term-time">
      <span>距离课程到期：</span>
      <el-button size="small" @click="search(7)">7天</el-button>
      <el-button size="small" @click="search(30)">30天</el-button>
      <el-input v-model="input" clearable placeholder="自定义天数"></el-input>
      <el-button size="small" @click="search(0)">筛选</el-button>
      <el-button size="small" class="reset" @click="reloads"><span>重置</span></el-button>
    </div>
  </div>
</template>

<script>
export default {
  props: {
    row: {
      type: Object,
      default: _ => {
        return {};
      }
    }
  },
  data() {
    return {
      input: ''
    }
  },
  methods: {
    // 筛选
    search: function(date) {
      if (date === 0) {
        date = this.input === '' ? 0 : this.input
      }
      const params = {
        page: 1,
        date: date
      };
      this.$store.dispatch('pageList/loadData', { params: params });
    },
    // 重置
    reloads() {
      const params = {
        page: 1,
        date: 0
      };
      this.input = '';
      this.$store.dispatch('pageList/loadData', { params: params });
    }
  }
};
</script>

<style lang="scss" scoped>
.title-item {
  width: max-content;
  margin-left: 25px;
  .picture {
    margin-right: 10px;
    padding-top: 60px;
    width: 80px;
    height: 0;
    position: relative;
    .el-image {
      width: 100%;
      height: 100%;
      position: absolute;
      left: 0;
      top: 0;
      ::v-deep.image-slot {
        height: 100%;
        font-size: 20px;
        color: #909399;
        background: #f5f7fa;
      }
    }
  }
  .info {
    flex: 1;
    flex-direction: column;
    height: 55px;
    .name {
      width: 182px;
      font-size: 14px;
      color: #333;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;
    }
  }
  .price {
    color: $price-color;
  }
  .scribing-price {
    color: $price-color;
    margin-right: 5px;
  }
  .free-price {
    color: $free-price-color;
  }
}
.term-time {
  width: auto;
  margin-top: 20px;
  .el-button {
    padding: 12px 20px;
  }
  .el-input {
    width: 20%;
    padding: 0 10px;
  }
  .reset {
    border-color: transparent;
    background-color: transparent;
    color: #c0c4cc;
    font-size: 14px;
  }
}
</style>
